/*
 * 使用Object构造函数创建实例
 */


// 使用 对象(instance-level)字面量 来隐式创建 Object类的实例
let x = {
    id: 1001,
    name: '朱某红' ,
    gender: '靓妹' ,
    age: 16
}

console.log( x );

// 显式调用Object类的构造函数来创建实例
let y = new Object(); 
console.log( y );
y.id = 2002 ;
y.name = '赵婷' ;
y.gender = '靓妹' ;
y.age = 18 ;

console.log( y );

console.log( '- - - - - - - - - - - - - - -' );

let o = new Object();
console.log( o );

// 如果给定值是 null 或 undefined，将会创建并返回一个空对象
let n = new Object( null );
console.log( n );

let u = new Object( undefined );
console.log( u );

console.log( '- - - - - - - - - - - - - - -' );

// 如果传进去的是一个基本类型的值(原始值)，则会构造其包装类型的对象(instance-level)
let first = new Object( 15 ); // number -> Number
console.log( first );

let second = new Object( '张婷' ); // string -> String
console.log( second );

let third = new Object( true ); // boolean -> Boolean
console.log( third );

let fourth = new Object( Symbol(null) ); // symbol -> Symbol
console.log( fourth );

let fifth = new Object( 100n ); // bigint -> BigInt
console.log( fifth );

console.log( '- - - - - - - - - - - - - - -' );

// 如果传进去的是引用类型的值，仍然会返回这个值，
// 经他们复制的变量保有和源对象(instance-level)相同的引用地址
let origin = {
    id: 1001 ,
    name: '朱亚红',
    gender: '女'
}

let target = new Object( origin );

console.log( target === origin );

target.name = '郑娅婷' ;

console.log( origin.name );


console.log( '- - - - - - - - - - - - - - - - - -' );

let t = new Object( { id: 3003, name: '王永年' , gender: '靓仔' } );
console.log( t );

// 当以非构造函数形式被调用时，Object 的行为等同于 new Object()
let p = Object( { id: 3003, name: '王永年' , gender: '靓仔' } );
console.log( p );
